package 线程的状态;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-11-21
 * Time: 10:59
 */
public class joinApply1 {
    public static int a = 0;
    public static int b = 0;
    //使用join 等待多个执行结果
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            try {
                Thread.sleep(1000);
                a = 10;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(2000);
                b = 20;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        //启动线程
        t1.start();
        t2.start();
        long start = System.currentTimeMillis();
        System.out.println(Thread.currentThread() + "join start");
        t2.join();
        System.out.println(Thread.currentThread() + "join t2 end");
        t1.join();
        System.out.println(Thread.currentThread() + "join t1 end");
        long end = System.currentTimeMillis();
        System.out.println("a : "+ a + "b : " + b + " cost :" + (end - start) + "ms");
    }

}
